﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Validity.Test.Constraints.StringConstraints
{
  [TestClass]
  public class HasMinimumLengthOfConstraint
    : ConstraintTestBase<ObjectStub>
  {
    public class Validator
      : ValidatorBase<ObjectStub>
    {
      public Validator()
      {
        DefineRulesFor(ctx => ctx.MyStringProperty1).HasMinimumLengthOf(5);
      }
    }

    public HasMinimumLengthOfConstraint() : base(new Validator(), 1) { }

    [TestMethod]
    public void TestConstraintVerified()
    {

      ValidateConstraintVerfied(CreateContext("12345"));
      ValidateConstraintVerfied(CreateContext("123456"));
      ValidateConstraintVerfied(CreateContext("      "));
      ValidateConstraintVerfied(CreateContext("123456"));
    }

    [TestMethod]
    public void TestConstraintViolated()
    {
      const String ruleViolation = "Must be at least 5 chacaters in length. Length = ";

      ValidateConstraintViolated(CreateContext(null), ruleViolation + "0");
      ValidateConstraintViolated(CreateContext(String.Empty), ruleViolation + "0");
      ValidateConstraintViolated(CreateContext(" "), ruleViolation + "1");
      ValidateConstraintViolated(CreateContext("1234"), ruleViolation + "4");
    }

    public ObjectStub CreateContext(String value)
    {
      var result = new ObjectStub();

      result.MyStringProperty1 = value;

      return result;
    }
  }
}
